<% if(session.getAttribute("email") == null) {
    response.sendRedirect("SignIn.jsp");
	 } else {
%>

<%@ include file="header.jsp" %>
<%@ page import="ServiceInterface.ServiceProxy" %>
<%@ page import="Beans.Movie" %>
<%@ page import="java.lang.reflect.Array" %>

<%@ page language="java" contentType="text/html; charset=US-ASCII"
    pageEncoding="US-ASCII"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
		<title>Sign-In</title>
		<script type="text/javascript" src="js/jquery.validate.js"></script>
		<script>
  			$(document).ready(function(){
    			$("#getBill").validate();
 			 });
 		</script>
	</head>
	<body>
		<div id="page-title">Bill</div><br>
		<% if(session.getAttribute("email") != null) { %>
    				<div id="user_id"> Currently signed in as: <%=session.getAttribute("email")%></div><br>
    	<%	} %>
    	<% if(session.getAttribute("alert") != null) { %>
    				<div id="alert"><%=session.getAttribute("alert")%></div><br><br>
    				<%  session.setAttribute("alert", "");%>
    	<%	} %>
    	
    	<% 	String qdone, membership_type;
    		Movie[] movies;
    		Object tmp_obj = session.getAttribute("email");
    		String email = tmp_obj.toString();
    		ServiceProxy proxy = new ServiceProxy();
    		proxy.setEndpoint("http://localhost:8079/VLMS3/services/Service");
    		membership_type = proxy.getMembershipType(email);
    		movies = proxy.generateBill(email);
    	%>
    	<br><br>
		<table cellspacing="1">
		<thead>
			<tr>
				<th>Movie ID</th>
				<th>Title</th>
				<th>Category</th>
			</tr>
		</thead>
		<tbody>
		<%	
			double totalFee = 0;
    		for(int i=0 ; i < movies.length ; i++) {
    			int movie_id		= movies[i].getMovieID();
    			String title 		= movies[i].getTitle();
    			String category 	= movies[i].getCategory();
    			totalFee += 10;  //need to pull actual fee from rental table
    	%>
		
			<tr>
				<td><%=movie_id%></td>
				<td><%=title%></td>
				<td><%=category%></td>
			</tr>
		<%
    		}
		%>
		</tbody>
		</table>
		<%
			if(membership_type.equalsIgnoreCase("premium")) {
		%>
			<div><b>Total Due: $10.00</b></div>
		<%
			} else {

				
		%>
			<div><b>Total Due: <%=totalFee%></b></div>
		<%		
			}
		%>
	</body>
</html>

<% } %>